﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XmlStudio.DataLayer {
    /// <summary>
    /// Represents item in xsd structure.
    /// </summary>
    public class XsdStructureItem {
        /// <summary>
        /// Gets or sets the type of element.
        /// </summary>
        public XsdElement ElementType { get; set; }

        /// <summary>
        /// Gets or sets the elements multiplicity.
        /// </summary>
        public Multiplicity Multiplicity { get; set; }

        /// <summary>
        /// Overriden so two structure items are compared by their content.
        /// </summary>
        /// <param name="obj">Another instance to compare.</param>
        /// <returns>True if both instances have the same content, false otherwise.</returns>
        public override bool Equals(object obj) {
            if(!(obj is XsdStructureItem))
                return false;

            if(obj == null)
                return false;

            XsdStructureItem t = (XsdStructureItem)obj;

            return (ElementType.Equals(t.ElementType) && Multiplicity.Equals(t.Multiplicity));
        }

        /// <summary>
        /// Returns the hashcode for the value of this instance.
        /// </summary>
        /// <returns>Hashcode.</returns>
        public override int GetHashCode() {
            return ElementType.GetHashCode() ^ Multiplicity.GetHashCode();
        }
    }
}
